package com.wangchao.administrator.zenmechi.ui.fragment.buyFragment;

import android.content.Context;

import com.wangchao.administrator.zenmechi.base.IView;

import java.util.List;

import rx.Subscriber;

/**
 * Created by cbb on 2016/10/18.
 * Email: 1023151857@qq.com
 */
public class buyPresenter implements BuyContract.Presenter {
    private buyModle modle;
    private adapterBuy adapter;
    private BuyContract.View view;

    public buyPresenter(BuyContract.View view) {
        this.view = view;
        this.modle = new buyModle();
    }

    //获取数据
    @Override
    public void getData(String market, final Context context) {
        modle.queryData(market, new Subscriber<List<BasketBean>>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                view.buyFailed("查询失败" + e.getMessage());
            }

            @Override
            public void onNext(List<BasketBean> basketBeen) {
                //Log.e("tag", "----------" + basketBeen.size());
                if (basketBeen != null && basketBeen.size() != 0) {
                    adapter = new adapterBuy(context, basketBeen);
                    view.buySuccess(adapter);
                } else
                    view.buySuccess(null);
            }
        });
    }

    //修改数据
    @Override
    public void setData(int position,int type) {
        modle.upData(position,type);
    }

    //清空数据
    @Override
    public void clearData(String name) {

    }

    @Override
    public void addData(String market, String url, String name, String price, int count) {
        modle.saveData(market, url, name, price, count);
    }

    @Override
    public void detachView() {

    }

    @Override
    public void attachView(IView view) {

    }
}
